{extend name="$lake_admin_layout"/}

{block name="main"}
<div class="layui-row">
    <div class="layui-col-md2 layui-col-sm12" style="padding:0 10px;">
        <div class="layui-card">
            <div class="layui-card-header layui-bg-cyan">栏目</div>
            <div class="layui-card-body">
                <div class="content-category" id="content_categorys">
                    <div class="lake-admin-cate-open-btn">
                        <a href="javascript:;" id="expand_all" data-open="true" title="全部展开/折叠">
                            <i class="iconfont icon-shiyongwendang"></i>
                            展开/折叠
                        </a> 
                    </div>
                    <div id="category_tree"></div>
                </div>
            </div>
        </div>
    </div>
    
    <div class="layui-col-md10 layui-col-sm12" style="padding:0 10px;">
        <div class="layui-card">
            <div class="layui-card-header layui-bg-cyan">
                <div class="layui-row">
                    <div class="layui-col-md12">
                        <span class="lakecms-top-title">
                            内容
                        </span>
                        
                        <a href="javascript:;" class="layui-btn layui-btn-sm layui-btn-light layui-batch-reload lake-admin-cate-reload" title="刷新">
                            <i class="iconfont icon-shuaxin"></i>
                        </a>
                        <a href="javascript:;" class="layui-btn layui-btn-sm layui-btn-light layui-batch-reload lake-admin-cate-homepage" title="首页">
                            <i class="iconfont icon-homepage"></i>
                        </a>
                    </div>
                </div>
            </div>
            <div class="layui-card-body">
                <iframe name="right" id="iframe_categorys_list" src="{:url('main')}" style="height: 100%; width:100%;border:none;" frameborder="0" scrolling="auto"></iframe>
            </div>
        </div>
    </div>
</div>
{/block}

{block name="script"}
<style>
.lake-admin-cate-open-btn {
    margin: 0;
    padding: 3px 8px;
    background: #f2f2f2;
}
.lake-admin-cate-open-btn a {
    display: block;
}
.lake-admin-cate-reload {
    float: right;
    margin-top: 5px;
}
.lake-admin-cate-homepage {
    float: right;
    margin-top: 5px;
    margin-right: 10px;
}
.cate-empty {
    text-align: left;
    padding: 5px;
}
.layui-tree-set-active > .layui-tree-entry .layui-tree-main {
    background: #f2f2f2;
}
</style>
<script type="text/javascript">
layui.config({
    base: "admin/libs/layui-extend/"
}).use(['jquery', 'notice', 'tree'], function() {
    var $ = layui.$,
        notice = layui.notice,
        tree = layui.tree;
    
    // 节点数据
    var data = {:json_encode($category)};
    
    tree.render({
        elem: '#category_tree',
        data: data,
        showCheckbox: false,
        id: 'category_tree_id',
        isJump: false,
        onlyIconControl: true,
        text: {
            none: '<div class="cate-empty">无</div>',
        },
        click: function(obj) {
            // 点击高亮
            $(".layui-tree-set").removeClass('layui-tree-set-active');
            obj.elem.addClass('layui-tree-set-active');
            
            if (obj.data.type == 2) {
                var url = '{:url("page")}?cateid=' + obj.data.id
            } else {
                var url = '{:url("cate")}?cateid=' + obj.data.id
            }
            
            $('#iframe_categorys_list').attr('src', url);
        }
    });
    
    $("#expand_all").click(function() {
        if ($(this).data("open")) {
            $('.layui-tree-setHide').find('.layui-tree-iconClick').trigger('click');
            $(this).data("open", false);
        } else {
            $('.layui-tree-spread').find('.layui-tree-iconClick').trigger('click');
            $(this).data("open", true);
        }
    });
    
    // 首页
    $(document).on("click", ".lake-admin-cate-homepage", function(e) {
        var url = "{:url('main')}";
        $('#iframe_categorys_list').attr('src', url);
    });
    
    // 刷新
    $(document).on("click", ".lake-admin-cate-reload", function(e) {
        e.preventDefault();
        e.stopPropagation();
        
        var iframe = $('#iframe_categorys_list');
        if (iframe[0].contentWindow) {
            var location = iframe[0].contentWindow.location;
            location.href = location.pathname + location.search;
        }
    });
});

var body_frame_height = parent.layui.$(".lake-admin-iframe-box").height()-100;
$(window).on('resize', function () {
    setTimeout(function () {
    body_frame_height = parent.layui.$(".lake-admin-iframe-box").height()-100;
        frameheight();
    }, 100);
});
function frameheight(){
  $("#content_categorys").height(body_frame_height);
  $("#iframe_categorys_list").height(body_frame_height);
}
(function (){
  frameheight();
})();
</script>
{/block}